

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Apache Configuration Directives &mdash; Mod_python v3.5.0-3.5.0 documentation</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '3.5.0-3.5.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <script type="text/javascript" src="_static/sidebar.js"></script>
    <link rel="author" title="About these documents" href="about.html" />
    <link rel="copyright" title="Copyright" href="copyright.html" />
    <link rel="top" title="Mod_python v3.5.0-3.5.0 documentation" href="index.html" />
    <link rel="next" title="Standard Handlers" href="handlers.html" />
    <link rel="prev" title="Python API" href="pythonapi.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="handlers.html" title="Standard Handlers"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="pythonapi.html" title="Python API"
             accesskey="P">previous</a> |</li>
        <li><a href="contents.html">Mod_python v3.5.0-3.5.0 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="apache-configuration-directives">
<span id="directives"></span><h1>Apache Configuration Directives<a class="headerlink" href="#apache-configuration-directives" title="Permalink to this headline">¶</a></h1>
<div class="section" id="request-handlers">
<span id="dir-handlers"></span><h2>Request Handlers<a class="headerlink" href="#request-handlers" title="Permalink to this headline">¶</a></h2>
<div class="section" id="python-handler-directive-syntax">
<span id="dir-handlers-syn"></span><h3>Python*Handler Directive Syntax<a class="headerlink" href="#python-handler-directive-syntax" title="Permalink to this headline">¶</a></h3>
<p id="index-0">All request handler directives have the following syntax:</p>
<p><tt class="docutils literal"><span class="pre">Python*Handler</span> <span class="pre">handler</span> <span class="pre">[handler</span> <span class="pre">...]</span> <span class="pre">[</span> <span class="pre">|</span> <span class="pre">.ext</span> <span class="pre">[.ext</span> <span class="pre">...]</span> <span class="pre">]</span></tt></p>
<p>Where <em>handler</em> is a callable object that accepts a single argument -
request object, and <em>.ext</em> is an optional file extension.</p>
<p>Multiple handlers can be specified on a single line, in which case
they will be called sequentially, from left to right. Same handler
directives can be specified multiple times as well, with the same
result - all handlers listed will be executed sequentially, from first
to last.</p>
<p>If any handler in the sequence returns a value other than
<tt class="docutils literal"><span class="pre">apache.OK</span></tt> or <tt class="docutils literal"><span class="pre">apache.DECLINED</span></tt>, then execution of all subsequent
handlers for that phase is aborted. What happens when either
<tt class="docutils literal"><span class="pre">apache.OK</span></tt> or <tt class="docutils literal"><span class="pre">apache.DECLINED</span></tt> is returned is dependent on which
phase is executing.</p>
<p>Note that prior to mod_python 3.3, if any handler in the sequence, no
matter which phase was executing, returned a value other than
<tt class="docutils literal"><span class="pre">apache.OK</span></tt>, then execution of all subsequent handlers for that phase
was aborted.</p>
<p>The list of handlers can optionally be followed by a <tt class="docutils literal"><span class="pre">|</span></tt> followed
by one or more file extensions. This would restrict the execution of
the handler to those file extensions only. This feature only works for
handlers executed after the trans phase.</p>
<p>A <em>handler</em> has the following syntax:</p>
<p><tt class="docutils literal"><span class="pre">module[::object]</span></tt></p>
<p>Where <em>module</em> can be a full module name (package dot notation is
accepted) or an actual path to a module code file. The module is loaded
using the mod_python module importer as implemented by the
<tt class="docutils literal"><span class="pre">apache.import_module()</span></tt> function. Reference should be made to
the documentation of that function for further details of how module
importing is managed.</p>
<p>The optional <em>object</em> is the name of an object inside the module.
Object can also contain dots, in which case it will be resolved from
left to right. During resolution, if mod_python encounters an object
of type <tt class="docutils literal"><span class="pre">&lt;class&gt;</span></tt>, it will try instantiating it passing it a single
argument, a request object.</p>
<p>If no object is specified, then it will default to the directive of
the handler, all lower case, with the word <tt class="docutils literal"><span class="pre">'python'</span></tt>
removed. E.g. the default object for PythonAuthenHandler would be
authenhandler.</p>
<p>Example:</p>
<div class="highlight-python"><pre>PythonAuthzHandler mypackage.mymodule::checkallowed</pre>
</div>
<p>For more information on handlers, see <a class="reference internal" href="pythonapi.html#pyapi-handler"><em>Overview of a Request Handler</em></a>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The <tt class="docutils literal"><span class="pre">'::'</span></tt> was chosen for performance reasons. In order
for Python to use objects inside modules, the modules first need to
be imported. Having the separator as simply a <tt class="docutils literal"><span class="pre">'.'</span></tt>, would
considerably complicate process of sequentially evaluating every
word to determine whether it is a package, module, class etc. Using
the (admittedly un-Python-like) <tt class="docutils literal"><span class="pre">'::'</span></tt> removes the time-consuming
work of figuring out where the module part ends and the object
inside of it begins, resulting in a modest performance gain.</p>
</div>
<p id="index-1">The handlers in this document are listed in order in which phases are
processed by Apache.</p>
</div>
<div class="section" id="python-handlers-and-python-path">
<span id="dir-handlers-pp"></span><h3>Python*Handlers and Python path<a class="headerlink" href="#python-handlers-and-python-path" title="Permalink to this headline">¶</a></h3>
<p id="index-2">If a <tt class="docutils literal"><span class="pre">Python*Handler</span></tt> directive is specified in a <em>directory section</em>
(i.e. inside a <tt class="docutils literal"><span class="pre">&lt;Directory&gt;&lt;/Directory&gt;</span></tt> or
<tt class="docutils literal"><span class="pre">&lt;DirectoryMatch&gt;&lt;/DirectoryMatch&gt;</span></tt> or in an <tt class="docutils literal"><span class="pre">.htaccess</span></tt> file),
then this directory is automatically prepended to the Python path
(<tt class="docutils literal"><span class="pre">sys.path</span></tt>) <em>unless</em> Python path is specified explicitely with the
<tt class="docutils literal"><span class="pre">PythonPath</span></tt> directive.</p>
<p>If a <tt class="docutils literal"><span class="pre">Python*Handler</span></tt> directive is specified in a <em>location section</em>
(i.e. inside <tt class="docutils literal"><span class="pre">&lt;Location&gt;&lt;/Location&gt;</span></tt> or
<tt class="docutils literal"><span class="pre">&lt;LocationMatch&gt;&lt;/LocationMatch&gt;</span></tt>), then no path modification is done
automatically and in most cases a <tt class="docutils literal"><span class="pre">PythonPath</span></tt> directive is required
to augment the path so that the handler module can be imported.</p>
<p>Also for <tt class="docutils literal"><span class="pre">Python*Handlers</span></tt> inside a location section mod_python
disables the phase of the request that maps the URI to a file on the
filesystem (<tt class="docutils literal"><span class="pre">ap_hook_map_to_storage</span></tt>). This is because there is
usually no link between path specified in <tt class="docutils literal"><span class="pre">&lt;Location&gt;</span></tt> and the
filesystem, while attempting to map to a filesystem location results
in unnecessary and expensive filesystem calls. Note that an important
side-effect of this is that once a request URI has been matched to a
<tt class="docutils literal"><span class="pre">&lt;Location&gt;</span></tt> containing a mod_python handler, all <tt class="docutils literal"><span class="pre">&lt;Directory&gt;</span></tt>
and <tt class="docutils literal"><span class="pre">&lt;DirectoryMatch&gt;</span></tt> directives and their contents are ignored for
this request.</p>
</div>
<div class="section" id="pythonpostreadrequesthandler">
<span id="dir-handlers-prrh"></span><h3>PythonPostReadRequestHandler<a class="headerlink" href="#pythonpostreadrequesthandler" title="Permalink to this headline">¶</a></h3>
<p id="index-3"><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> <em>Python*Handler Syntax</em> <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>This handler is called after the request has been read but before any
other phases have been processed. This is useful to make decisions
based upon the input header fields.</p>
<p>Where multiple handlers are specified, if any handler in the sequence
returns a value other than <tt class="docutils literal"><span class="pre">apache.OK</span></tt> or <tt class="docutils literal"><span class="pre">apache.DECLINED</span></tt>, then
execution of all subsequent handlers for this phase is aborted.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">When this phase of the request is processed, the URI has not yet
been translated into a path name, therefore this directive could
never be executed by Apache if it could specified within
<tt class="docutils literal"><span class="pre">&lt;Directory&gt;</span></tt>, <tt class="docutils literal"><span class="pre">&lt;Location&gt;</span></tt>, <tt class="docutils literal"><span class="pre">&lt;File&gt;</span></tt> directives or in an
<tt class="file docutils literal"><span class="pre">.htaccess</span></tt> file. The only place this directive is allowed is
the main configuration file, and the code for it will execute in
the main interpreter. And because this phase happens before any
identification of the type of content being requested is done
(i.e. is this a python program or a gif?), the python routine
specified with this handler will be called for <em>ALL</em> requests on
this server (not just python programs), which is an important
consideration if performance is a priority.</p>
</div>
</div>
<div class="section" id="pythontranshandler">
<span id="dir-handlers-th"></span><h3>PythonTransHandler<a class="headerlink" href="#pythontranshandler" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> <em>Python*Handler Syntax</em> <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>This handler allows for an opportunity to translate the URI into
an actual filename, before the server&#8217;s default rules (Alias
directives and the like) are followed.</p>
<p>Where multiple handlers are specified, if any handler in the sequence
returns a value other than <tt class="docutils literal"><span class="pre">apache.DECLINED</span></tt>, then execution of all
subsequent handlers for this phase is aborted.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">At the time when this phase of the request is being processed, the
URI has not been translated into a path name, therefore this
directive will never be executed by Apache if specified within
<tt class="docutils literal"><span class="pre">&lt;Directory&gt;</span></tt>, <tt class="docutils literal"><span class="pre">&lt;Location&gt;</span></tt>, <tt class="docutils literal"><span class="pre">&lt;File&gt;</span></tt> directives or in an
<tt class="file docutils literal"><span class="pre">.htaccess</span></tt> file. The only place this can be specified is the
main configuration file, and the code for it will execute in the
main interpreter.</p>
</div>
</div>
<div class="section" id="pythonheaderparserhandler">
<span id="dir-handlers-hph"></span><h3>PythonHeaderParserHandler<a class="headerlink" href="#pythonheaderparserhandler" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> <em>Python*Handler Syntax</em> <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>This handler is called to give the module a chance to look at the
request headers and take any appropriate specific actions early in the
processing sequence.</p>
<p>Where multiple handlers are specified, if any handler in the sequence
returns a value other than <tt class="docutils literal"><span class="pre">apache.OK</span></tt> or <tt class="docutils literal"><span class="pre">apache.DECLINED</span></tt>, then
execution of all subsequent handlers for this phase is aborted.</p>
</div>
<div class="section" id="pythoninithandler">
<span id="dir-handlers-pih"></span><h3>PythonInitHandler<a class="headerlink" href="#pythoninithandler" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> <em>Python*Handler Syntax</em> <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>This handler is the first handler called in the request processing
phases that is allowed both inside and outside :file`.htaccess` and
directory.</p>
<p>Where multiple handlers are specified, if any handler in the sequence
returns a value other than <tt class="docutils literal"><span class="pre">apache.OK</span></tt> or <tt class="docutils literal"><span class="pre">apache.DECLINED</span></tt>, then
execution of all subsequent handlers for this phase is aborted.</p>
<p>This handler is actually an alias to two different handlers. When
specified in the main config file outside any directory tags, it is an
alias to <tt class="docutils literal"><span class="pre">PostReadRequestHandler</span></tt>. When specified inside directory
(where <tt class="docutils literal"><span class="pre">PostReadRequestHandler</span></tt> is not allowed), it aliases to
<tt class="docutils literal"><span class="pre">PythonHeaderParserHandler</span></tt>.</p>
<p>*(This idea was borrowed from mod_perl)</p>
</div>
<div class="section" id="pythonaccesshandler">
<span id="dir-handlers-ach"></span><h3>PythonAccessHandler<a class="headerlink" href="#pythonaccesshandler" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> <em>Python*Handler Syntax</em> <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>This routine is called to check for any module-specific restrictions
placed upon the requested resource.</p>
<p>Where multiple handlers are specified, if any handler in the sequence
returns a value other than <tt class="docutils literal"><span class="pre">apache.OK</span></tt> or <tt class="docutils literal"><span class="pre">apache.DECLINED</span></tt>, then
execution of all subsequent handlers for this phase is aborted.</p>
<p>For example, this can be used to restrict access by IP number. To do
so, you would return <tt class="docutils literal"><span class="pre">HTTP_FORBIDDEN</span></tt> or some such to indicate
that access is not allowed.</p>
</div>
<div class="section" id="pythonauthenhandler">
<span id="dir-handlers-auh"></span><h3>PythonAuthenHandler<a class="headerlink" href="#pythonauthenhandler" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> <em>Python*Handler Syntax</em> <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>This routine is called to check the authentication information sent
with the request (such as looking up the user in a database and
verifying that the [encrypted] password sent matches the one in the
database).</p>
<p>Where multiple handlers are specified, if any handler in the sequence
returns a value other than <tt class="docutils literal"><span class="pre">apache.DECLINED</span></tt>, then execution of all
subsequent handlers for this phase is aborted.</p>
<p>To obtain the username, use <tt class="docutils literal"><span class="pre">req.user</span></tt>. To obtain the password
entered by the user, use the <tt class="xref py py-meth docutils literal"><span class="pre">request.get_basic_auth_pw()</span></tt> function.</p>
<p>A return of <tt class="docutils literal"><span class="pre">apache.OK</span></tt> means the authentication succeeded. A return
of <tt class="docutils literal"><span class="pre">apache.HTTP_UNAUTHORIZED</span></tt> with most browser will bring up the
password dialog box again. A return of <tt class="docutils literal"><span class="pre">apache.HTTP_FORBIDDEN</span></tt> will
usually show the error on the browser and not bring up the password
dialog <tt class="docutils literal"><span class="pre">again.</span> <span class="pre">HTTP_FORBIDDEN</span></tt> should be used when authentication
succeeded, but the user is not permitted to access a particular URL.</p>
<p>An example authentication handler might look like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">authenhandler</span><span class="p">(</span><span class="n">req</span><span class="p">):</span>

    <span class="n">pw</span> <span class="o">=</span> <span class="n">req</span><span class="o">.</span><span class="n">get_basic_auth_pw</span><span class="p">()</span>
    <span class="n">user</span> <span class="o">=</span> <span class="n">req</span><span class="o">.</span><span class="n">user</span>
    <span class="k">if</span> <span class="n">user</span> <span class="o">==</span> <span class="s">&quot;spam&quot;</span> <span class="ow">and</span> <span class="n">pw</span> <span class="o">==</span> <span class="s">&quot;eggs&quot;</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">apache</span><span class="o">.</span><span class="n">OK</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">apache</span><span class="o">.</span><span class="n">HTTP_UNAUTHORIZED</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><tt class="xref py py-meth docutils literal"><span class="pre">request.get_basic_auth_pw()</span></tt> must be called prior to using the
<tt class="xref py py-attr docutils literal"><span class="pre">request.user</span></tt> value. Apache makes no attempt to decode the
authentication information unless <tt class="xref py py-meth docutils literal"><span class="pre">request.get_basic_auth_pw()</span></tt> is called.</p>
</div>
</div>
<div class="section" id="pythonauthzhandler">
<span id="dir-handlers-auzh"></span><h3>PythonAuthzHandler<a class="headerlink" href="#pythonauthzhandler" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> <em>Python*Handler Syntax</em> <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>This handler runs after AuthenHandler and is intended for checking
whether a user is allowed to access a particular resource. But more
often than not it is done right in the AuthenHandler.</p>
<p>Where multiple handlers are specified, if any handler in the sequence
returns a value other than <tt class="docutils literal"><span class="pre">apache.DECLINED</span></tt>, then execution of all
subsequent handlers for this phase is aborted.</p>
</div>
<div class="section" id="pythontypehandler">
<span id="dir-handlers-tph"></span><h3>PythonTypeHandler<a class="headerlink" href="#pythontypehandler" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> <em>Python*Handler Syntax</em> <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>This routine is called to determine and/or set the various document
type information bits, like Content-type (via <tt class="docutils literal"><span class="pre">r-&gt;content_type</span></tt>),
language, et cetera.</p>
<p>Where multiple handlers are specified, if any handler in the sequence
returns a value other than <tt class="docutils literal"><span class="pre">apache.DECLINED</span></tt>, then execution of all
subsequent handlers for this phase is aborted.</p>
</div>
<div class="section" id="pythonfixuphandler">
<span id="dir-handlers-fuh"></span><h3>PythonFixupHandler<a class="headerlink" href="#pythonfixuphandler" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> <em>Python*Handler Syntax</em> <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>This routine is called to perform any module-specific fixing of header
fields, et cetera. It is invoked just before any content-handler.</p>
<p>Where multiple handlers are specified, if any handler in the sequence
returns a value other than <tt class="docutils literal"><span class="pre">apache.OK</span></tt> or <tt class="docutils literal"><span class="pre">apache.DECLINED</span></tt>, then
execution of all subsequent handlers for this phase is aborted.</p>
</div>
<div class="section" id="pythonhandler">
<span id="dir-handlers-ph"></span><h3>PythonHandler<a class="headerlink" href="#pythonhandler" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> <em>Python*Handler Syntax</em> <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>This is the main request handler. Many applications will only provide
this one handler.</p>
<p>Where multiple handlers are specified, if any handler in the sequence
returns a status value other than <tt class="docutils literal"><span class="pre">apache.OK</span></tt> or
<tt class="docutils literal"><span class="pre">apache.DECLINED</span></tt>, then execution of subsequent handlers for the phase
are skipped and the return status becomes that for the whole content
handler phase. If all handlers are run, the return status of the final
handler is what becomes the return status of the whole content handler
phase. Where that final status is <tt class="docutils literal"><span class="pre">apache.DECLINED</span></tt>, Apache will fall
back to using the <tt class="docutils literal"><span class="pre">default-handler</span></tt> and attempt to serve up the target
as a static file.</p>
</div>
<div class="section" id="pythonloghandler">
<span id="dir-handlers-plh"></span><h3>PythonLogHandler<a class="headerlink" href="#pythonloghandler" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> <em>Python*Handler Syntax</em> <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>This routine is called to perform any module-specific logging
activities.</p>
<p>Where multiple handlers are specified, if any handler in the sequence
returns a value other than <tt class="docutils literal"><span class="pre">apache.OK</span></tt> or <tt class="docutils literal"><span class="pre">apache.DECLINED</span></tt>, then
execution of all subsequent handlers for this phase is aborted.</p>
</div>
<div class="section" id="pythoncleanuphandler">
<span id="dir-handlers-pch"></span><h3>PythonCleanupHandler<a class="headerlink" href="#pythoncleanuphandler" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> <em>Python*Handler Syntax</em> <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>This is the very last handler, called just before the request object
is destroyed by Apache.</p>
<p>Unlike all the other handlers, the return value of this handler is
ignored. Any errors will be logged to the error log, but will not be
sent to the client, even if PythonDebug is On.</p>
<p>This handler is not a valid argument to the <tt class="docutils literal"><span class="pre">rec.add_handler()</span></tt>
function. For dynamic clean up registration, use
<tt class="docutils literal"><span class="pre">req.register_cleanup()</span></tt>.</p>
<p>Once cleanups have started, it is not possible to register more of
them. Therefore, <tt class="docutils literal"><span class="pre">req.register_cleanup()</span></tt> has no effect within this
handler.</p>
<p>Cleanups registered with this directive will execute <em>after</em> cleanups
registered with <tt class="docutils literal"><span class="pre">req.register_cleanup()</span></tt>.</p>
</div>
</div>
<div class="section" id="filters">
<span id="dir-filter"></span><h2>Filters<a class="headerlink" href="#filters" title="Permalink to this headline">¶</a></h2>
<div class="section" id="pythoninputfilter">
<span id="dir-filter-if"></span><h3>PythonInputFilter<a class="headerlink" href="#pythoninputfilter" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> PythonInputFilter handler name <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>Registers an input filter <em>handler</em> under name <em>name</em>. <em>Handler</em> is a
module name optionally followed <tt class="docutils literal"><span class="pre">::</span></tt> and a callable object name. If
callable object name is omitted, it will default to
<tt class="docutils literal"><span class="pre">'inputfilter'</span></tt>. <em>Name</em> is the name under which the filter is
registered, by convention filter names are usually in all caps.</p>
<p>The <em>module</em> referred to by the handler can be a full module name
(package dot notation is accepted) or an actual path to a module code file.
The module is loaded using the mod_python module importer as implemented by
the <a class="reference internal" href="pythonapi.html#apache.import_module" title="apache.import_module"><tt class="xref py py-func docutils literal"><span class="pre">apache.import_module()</span></tt></a> function. Reference should be made to the
documentation of that function for further details of how module importing
is managed.</p>
<p>To activate the filter, use the <tt class="docutils literal"><span class="pre">AddInputFilter</span></tt> directive.</p>
</div>
<div class="section" id="pythonoutputfilter">
<span id="dir-filter-of"></span><h3>PythonOutputFilter<a class="headerlink" href="#pythonoutputfilter" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> PythonOutputFilter handler name <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>Registers an output filter <em>handler</em> under name <em>name</em>. <em>handler</em> is a
module name optionally followed <tt class="docutils literal"><span class="pre">::</span></tt> and a callable object name. If
callable object name is omitted, it will default to
<tt class="docutils literal"><span class="pre">'outputfilter'</span></tt>. <em>name</em> is the name under which the filter is
registered, by convention filter names are usually in all caps.</p>
<p>The <em>module</em> referred to by the handler can be a full module name
(package dot notation is accepted) or an actual path to a module code file.
The module is loaded using the mod_python module importer as implemented by
the <a class="reference internal" href="pythonapi.html#apache.import_module" title="apache.import_module"><tt class="xref py py-func docutils literal"><span class="pre">apache.import_module()</span></tt></a> function. Reference should be made to the
documentation of that function for further details of how module importing
is managed.</p>
<p>To activate the filter, use the <tt class="docutils literal"><span class="pre">AddOutputFilter</span></tt> directive.</p>
</div>
</div>
<div class="section" id="connection-handler">
<span id="dir-conn"></span><h2>Connection Handler<a class="headerlink" href="#connection-handler" title="Permalink to this headline">¶</a></h2>
<div class="section" id="pythonconnectionhandler">
<span id="dir-conn-ch"></span><h3>PythonConnectionHandler<a class="headerlink" href="#pythonconnectionhandler" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> PythonConnectionHandler handler <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>Specifies that the connection should be handled with <em>handler</em>
connection handler. <em>handler</em> will be passed a single argument -
the connection object.</p>
<p><em>Handler</em> is a module name optionally followed <tt class="docutils literal"><span class="pre">::</span></tt> and a
callable object name. If callable object name is omitted, it will
default to <tt class="docutils literal"><span class="pre">'connectionhandler'</span></tt>.</p>
<p>The <em>module</em> can be a full module name (package dot notation is
accepted) or an absolute path to a module code file. The module is loaded
using the mod_python module importer as implemented by the
<a class="reference internal" href="pythonapi.html#apache.import_module" title="apache.import_module"><tt class="xref py py-func docutils literal"><span class="pre">apache.import_module()</span></tt></a> function. Reference should be made to the
documentation of that function for further details of how module importing
is managed.</p>
</div>
</div>
<div class="section" id="other-directives">
<span id="dir-other"></span><h2>Other Directives<a class="headerlink" href="#other-directives" title="Permalink to this headline">¶</a></h2>
<div class="section" id="pythonenablepdb">
<span id="dir-other-epd"></span><h3>PythonEnablePdb<a class="headerlink" href="#pythonenablepdb" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> PythonEnablePdb {On, Off} <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Default">Default:</a> PythonEnablePdb Off <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>When On, mod_python will execute the handler functions within the
Python debugger pdb using the <tt class="xref py py-func docutils literal"><span class="pre">pdb.runcall()</span></tt> function.</p>
<p>Because pdb is an interactive tool, start httpd from the command line
with the <tt class="docutils literal"><span class="pre">-DONE_PROCESS</span></tt> option when using this directive. As soon as
your handler code is entered, you will see a Pdb prompt allowing you
to step through the code and examine variables.</p>
</div>
<div class="section" id="pythondebug">
<span id="dir-other-pd"></span><h3>PythonDebug<a class="headerlink" href="#pythondebug" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> PythonDebug {On, Off} <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Default">Default:</a> PythonDebug Off <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>Normally, the traceback output resulting from uncaught Python errors
is sent to the error log. With PythonDebug On directive specified, the
output will be sent to the client (as well as the log), except when
the error is <tt class="xref py py-exc docutils literal"><span class="pre">IOError</span></tt> while writing, in which case it will go
to the error log.</p>
<p>This directive is very useful during the development process. It is
recommended that you do not use it production environment as it may
reveal to the client unintended, possibly sensitive security
information.</p>
</div>
<div class="section" id="pythonimport">
<span id="dir-other-pimp"></span><h3>PythonImport<a class="headerlink" href="#pythonimport" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> PythonImport <em>module</em> <em>interpreter_name</em> <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>Tells the server to import the Python module module at process startup
under the specified interpreter name. The import takes place at child
process initialization, so the module will actually be imported once for
every child process spawned.</p>
<p>The <em>module</em> can be a full module name (package dot notation is
accepted) or an absolute path to a module code file. The module is loaded
using the mod_python module importer as implemented by the
<a class="reference internal" href="pythonapi.html#apache.import_module" title="apache.import_module"><tt class="xref py py-func docutils literal"><span class="pre">apache.import_module()</span></tt></a> function. Reference should be made to
the documentation of that function for further details of how module
importing is managed.</p>
<p>The <tt class="docutils literal"><span class="pre">PythonImport</span></tt> directive is useful for initialization tasks that
could be time consuming and should not be done at the time of processing a
request, e.g. initializing a database connection. Where such initialization
code could fail and cause the importing of the module to fail, it should be
placed in its own function and the alternate syntax used:</p>
<p><tt class="docutils literal"><span class="pre">PythonImport</span> <span class="pre">*module::function*</span> <span class="pre">*interpreter_name*</span></tt></p>
<p>The named function will be called only after the module has been imported
successfully. The function will be called with no arguments.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">At the time when the import takes place, the configuration is not
completely read yet, so all other directives, including
PythonInterpreter have no effect on the behavior of modules
imported by this directive. Because of this limitation, the
interpreter must be specified explicitly, and must match the name
under which subsequent requests relying on this operation will
execute. If you are not sure under what interpreter name a request
is running, examine the <tt class="xref py py-attr docutils literal"><span class="pre">request.interpreter</span></tt> member of the request
object.</p>
</div>
<p>See also Multiple Interpreters.</p>
</div>
<div class="section" id="pythoninterpperdirectory">
<span id="dir-other-ipd"></span><h3>PythonInterpPerDirectory<a class="headerlink" href="#pythoninterpperdirectory" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> PythonInterpPerDirectory {On, Off} <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Default">Default:</a> PythonInterpPerDirectory Off <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>Instructs mod_python to name subinterpreters using the directory of
the file in the request (<tt class="docutils literal"><span class="pre">req.filename</span></tt>) rather than the the
server name. This means that scripts in different directories will
execute in different subinterpreters as opposed to the default policy
where scripts in the same virtual server execute in the same
subinterpreter, even if they are in different directories.</p>
<p>For example, assume there is a
<tt class="file docutils literal"><span class="pre">/directory/subdirectory</span></tt>. <tt class="file docutils literal"><span class="pre">/directory</span></tt> has an
<tt class="docutils literal"><span class="pre">.htaccess</span></tt> file with a <tt class="docutils literal"><span class="pre">PythonHandler</span></tt> directive.
<tt class="file docutils literal"><span class="pre">/directory/subdirectory</span></tt> doesn&#8217;t have an <tt class="docutils literal"><span class="pre">.htaccess</span></tt>. By
default, scripts in <tt class="file docutils literal"><span class="pre">/directory</span></tt> and
<tt class="file docutils literal"><span class="pre">/directory/subdirectory</span></tt> would execute in the same interpreter
assuming both directories are accessed via the same virtual
server. With <tt class="docutils literal"><span class="pre">PythonInterpPerDirectory</span></tt>, there would be two
different interpreters, one for each directory.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">In early phases of the request prior to the URI translation
(PostReadRequestHandler and TransHandler) the path is not yet known
because the URI has not been translated. During those phases and
with PythonInterpPerDirectory on, all python code gets executed in
the main interpreter. This may not be exactly what you want, but
unfortunately there is no way around this.</p>
</div>
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="pythonapi.html#pyapi-interps"><em>Multiple Interpreters</em></a></dt>
<dd>for more information</dd>
</dl>
</div>
</div>
<div class="section" id="pythoninterpperdirective">
<span id="dir-other-ipdv"></span><h3>PythonInterpPerDirective<a class="headerlink" href="#pythoninterpperdirective" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> PythonInterpPerDirective {On, Off} <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Default">Default:</a> PythonInterpPerDirective Off <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>Instructs mod_python to name subinterpreters using the directory in
which the Python*Handler directive currently in effect was
encountered.</p>
<p>For example, assume there is a
<tt class="file docutils literal"><span class="pre">/directory/subdirectory</span></tt>. <tt class="file docutils literal"><span class="pre">/directory</span></tt> has an <tt class="docutils literal"><span class="pre">.htaccess</span></tt>
file with a <tt class="docutils literal"><span class="pre">PythonHandler</span></tt> directive.  <tt class="file docutils literal"><span class="pre">/directory/subdirectory</span></tt>
has another <tt class="file docutils literal"><span class="pre">.htaccess</span></tt> file with another <tt class="docutils literal"><span class="pre">PythonHandler</span></tt>. By
default, scripts in <tt class="file docutils literal"><span class="pre">/directory</span></tt> and
<tt class="file docutils literal"><span class="pre">/directory/subdirectory</span></tt> would execute in the same interpreter
assuming both directories are in the same virtual server. With
<tt class="docutils literal"><span class="pre">PythonInterpPerDirective</span></tt>, there would be two different interpreters,
one for each directive.</p>
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="pythonapi.html#pyapi-interps"><em>Multiple Interpreters</em></a></dt>
<dd>for more information</dd>
</dl>
</div>
</div>
<div class="section" id="pythoninterpreter">
<span id="dir-other-pi"></span><h3>PythonInterpreter<a class="headerlink" href="#pythoninterpreter" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> PythonInterpreter <em>name</em> <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>Forces mod_python to use interpreter named <em>name</em>, overriding the
default behaviour or behaviour dictated by a <a class="reference internal" href="#dir-other-ipd"><em>PythonInterpPerDirectory</em></a> or
<a class="reference internal" href="#dir-other-ipdv"><em>PythonInterpPerDirective</em></a> direcive.</p>
<p>This directive can be used to force execution that would normally
occur in different subinterpreters to run in the same one. When
specified in the DocumentRoot, it forces the whole server to run in one
subinterpreter.</p>
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="pythonapi.html#pyapi-interps"><em>Multiple Interpreters</em></a></dt>
<dd>for more information</dd>
</dl>
</div>
</div>
<div class="section" id="pythonhandlermodule">
<span id="dir-other-phm"></span><h3>PythonHandlerModule<a class="headerlink" href="#pythonhandlermodule" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> PythonHandlerModule <em>module</em> <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>PythonHandlerModule can be used an alternative to Python*Handler
directives. The module specified in this handler will be searched for
existence of functions matching the default handler function names,
and if a function is found, it will be executed.</p>
<p>For example, instead of:</p>
<div class="highlight-python"><pre>PythonAuthenHandler mymodule
PythonHandler mymodule
PythonLogHandler mymodule</pre>
</div>
<p>one can simply use:</p>
<div class="highlight-python"><pre>PythonHandlerModule mymodule</pre>
</div>
</div>
<div class="section" id="pythonautoreload">
<span id="dir-other-par"></span><h3>PythonAutoReload<a class="headerlink" href="#pythonautoreload" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> PythonAutoReload {On, Off} <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Default">Default:</a> PythonAutoReload On <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>If set to Off, instructs mod_python not to check the modification date
of the module file.</p>
<p>By default, mod_python checks the time-stamp of the file and reloads
the module if the module&#8217;s file modification date is later than the
last import or reload. This way changed modules get automatically
reimported, eliminating the need to restart the server for every
change.</p>
<p>Disabling autoreload is useful in production environment where the
modules do not change; it will save some processing time and give a
small performance gain.</p>
</div>
<div class="section" id="pythonoptimize">
<span id="dir-other-pomz"></span><h3>PythonOptimize<a class="headerlink" href="#pythonoptimize" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> PythonOptimize {On, Off} <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Default">Default:</a> PythonOptimize Off <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>Enables Python optimization. Same as the Python <tt class="docutils literal"><span class="pre">-O</span></tt> option.</p>
</div>
<div class="section" id="pythonoption">
<span id="dir-other-po"></span><h3>PythonOption<a class="headerlink" href="#pythonoption" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> PythonOption key [value] <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>Assigns a key value pair to a table that can be later retrieved by the
<tt class="xref py py-meth docutils literal"><span class="pre">request.get_options()</span></tt> function. This is useful to pass information
between the apache configuration files (<tt class="file docutils literal"><span class="pre">httpd.conf</span></tt>,
<tt class="file docutils literal"><span class="pre">.htaccess</span></tt>, etc) and the Python programs. If the value is omitted or empty (<tt class="docutils literal"><span class="pre">&quot;&quot;</span></tt>),
then the key is removed from the local configuration.</p>
<div class="section" id="reserved-pythonoption-keywords">
<h4>Reserved PythonOption Keywords<a class="headerlink" href="#reserved-pythonoption-keywords" title="Permalink to this headline">¶</a></h4>
<p>Some <tt class="docutils literal"><span class="pre">PythonOption</span></tt> keywords are used for configuring various aspects of
mod_python. Any keyword starting with mod_python.* should be considered
as reserved for internal mod_python use.</p>
<p>Users are encouraged to use their own namespace qualifiers when creating
add-on modules, and not pollute the global namespace.</p>
<p>The following PythonOption keys are currently used by mod_python.</p>
<div class="line-block">
<div class="line">mod_python.mutex_directory</div>
<div class="line">mod_python.mutex_locks</div>
<div class="line">mod_python.psp.cache_database_filename</div>
<div class="line">mod_python.session.session_type</div>
<div class="line">mod_python.session.cookie_name</div>
<div class="line">mod_python.session.application_domain</div>
<div class="line">mod_python.session.application_path</div>
<div class="line">mod_python.session.database_directory</div>
<div class="line">mod_python.dbm_session.database_filename</div>
<div class="line">mod_python.dbm_session.database_directory</div>
<div class="line">mod_python.file_session.enable_fast_cleanup</div>
<div class="line">mod_python.file_session.verify_session_timeout</div>
<div class="line">mod_python.file_session.cleanup_grace_period</div>
<div class="line">mod_python.file_session.cleanup_time_limit</div>
<div class="line">mod_python.file_session.database_directory</div>
<div class="line">mod_python.wsgi.application</div>
<div class="line">mod_python.wsgi.base_uri</div>
</div>
<div class="line-block">
<div class="line">session <em>Deprecated in 3.3, use mod_python.session.session_type</em></div>
<div class="line">ApplicationPath <em>Deprecated in 3.3, use mod_python.session.application_path</em></div>
<div class="line">session_cookie_name <em>Deprecated in 3.3, use mod_python.session.cookie_name</em></div>
<div class="line">session_directory <em>Deprecated in 3.3, use mod_python.session.database_directory</em></div>
<div class="line">session_dbm <em>Deprecated in 3.3, use mod_python.dbm_session.database_filename</em></div>
<div class="line">session_cleanup_time_limit <em>Deprecated in 3.3, use mod_python.file_session.cleanup_time_limit</em></div>
<div class="line">session_fast_cleanup <em>Deprecated in 3.3, use mod_python.file_session.enable_fast_cleanup</em></div>
<div class="line">session_grace_period <em>Deprecated in 3.3, use mod_python.file_session.cleanup_grace_period</em></div>
<div class="line">session_verify_cleanup <em>Deprecated in 3.3, use mod_python.file_session.cleanup_session_timeout</em></div>
<div class="line">PSPDbmCache <em>Deprecated in 3.3, use mod_python.psp.cache_database_filename</em></div>
</div>
</div>
</div>
<div class="section" id="pythonpath">
<span id="dir-other-pp"></span><h3>PythonPath<a class="headerlink" href="#pythonpath" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Syntax">Syntax:</a> PythonPath <em>path</em> <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Context">Context:</a> server config, virtual host, directory, htaccess <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Override">Override:</a> not None <br />
<a class="reference external" href="http://httpd.apache.org/docs-2.4/mod/directive-dict.html#Module">Module:</a> mod_python.c <br /></p>
<p>PythonPath directive sets the PythonPath. The path must be specified
in Python list notation, e.g.:</p>
<div class="highlight-python"><pre>PythonPath "['/usr/local/lib/python2.0', '/usr/local/lib/site_python', '/some/other/place']"</pre>
</div>
<p>The path specified in this directive will replace the path, not add to
it. However, because the value of the directive is evaled, to append a
directory to the path, one can specify something like:</p>
<div class="highlight-python"><pre>PythonPath "sys.path+['/mydir']"</pre>
</div>
<p>Mod_python tries to minimize the number of evals associated with the
PythonPath directive because evals are slow and can negatively impact
performance, especially when the directive is specified in an
<tt class="file docutils literal"><span class="pre">.htaccess</span></tt> file which gets parsed at every hit. Mod_python will
remember the arguments to the PythonPath directive in the un-evaled
form, and before evaling the value it will compare it to the
remembered value. If the value is the same, no action is
taken. Because of this, you should not rely on the directive as a way
to restore the pythonpath to some value if your code changes it.</p>
<p>When multiple PythonPath directives are specified, the effect is not
cumulative, last directive will override all previous ones.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This directive should not be used as a security measure since the
Python path is easily manipulated from within the scripts.</p>
</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Apache Configuration Directives</a><ul>
<li><a class="reference internal" href="#request-handlers">Request Handlers</a><ul>
<li><a class="reference internal" href="#python-handler-directive-syntax">Python*Handler Directive Syntax</a></li>
<li><a class="reference internal" href="#python-handlers-and-python-path">Python*Handlers and Python path</a></li>
<li><a class="reference internal" href="#pythonpostreadrequesthandler">PythonPostReadRequestHandler</a></li>
<li><a class="reference internal" href="#pythontranshandler">PythonTransHandler</a></li>
<li><a class="reference internal" href="#pythonheaderparserhandler">PythonHeaderParserHandler</a></li>
<li><a class="reference internal" href="#pythoninithandler">PythonInitHandler</a></li>
<li><a class="reference internal" href="#pythonaccesshandler">PythonAccessHandler</a></li>
<li><a class="reference internal" href="#pythonauthenhandler">PythonAuthenHandler</a></li>
<li><a class="reference internal" href="#pythonauthzhandler">PythonAuthzHandler</a></li>
<li><a class="reference internal" href="#pythontypehandler">PythonTypeHandler</a></li>
<li><a class="reference internal" href="#pythonfixuphandler">PythonFixupHandler</a></li>
<li><a class="reference internal" href="#pythonhandler">PythonHandler</a></li>
<li><a class="reference internal" href="#pythonloghandler">PythonLogHandler</a></li>
<li><a class="reference internal" href="#pythoncleanuphandler">PythonCleanupHandler</a></li>
</ul>
</li>
<li><a class="reference internal" href="#filters">Filters</a><ul>
<li><a class="reference internal" href="#pythoninputfilter">PythonInputFilter</a></li>
<li><a class="reference internal" href="#pythonoutputfilter">PythonOutputFilter</a></li>
</ul>
</li>
<li><a class="reference internal" href="#connection-handler">Connection Handler</a><ul>
<li><a class="reference internal" href="#pythonconnectionhandler">PythonConnectionHandler</a></li>
</ul>
</li>
<li><a class="reference internal" href="#other-directives">Other Directives</a><ul>
<li><a class="reference internal" href="#pythonenablepdb">PythonEnablePdb</a></li>
<li><a class="reference internal" href="#pythondebug">PythonDebug</a></li>
<li><a class="reference internal" href="#pythonimport">PythonImport</a></li>
<li><a class="reference internal" href="#pythoninterpperdirectory">PythonInterpPerDirectory</a></li>
<li><a class="reference internal" href="#pythoninterpperdirective">PythonInterpPerDirective</a></li>
<li><a class="reference internal" href="#pythoninterpreter">PythonInterpreter</a></li>
<li><a class="reference internal" href="#pythonhandlermodule">PythonHandlerModule</a></li>
<li><a class="reference internal" href="#pythonautoreload">PythonAutoReload</a></li>
<li><a class="reference internal" href="#pythonoptimize">PythonOptimize</a></li>
<li><a class="reference internal" href="#pythonoption">PythonOption</a><ul>
<li><a class="reference internal" href="#reserved-pythonoption-keywords">Reserved PythonOption Keywords</a></li>
</ul>
</li>
<li><a class="reference internal" href="#pythonpath">PythonPath</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="pythonapi.html"
                        title="previous chapter">Python API</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="handlers.html"
                        title="next chapter">Standard Handlers</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/directives.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="handlers.html" title="Standard Handlers"
             >next</a> |</li>
        <li class="right" >
          <a href="pythonapi.html" title="Python API"
             >previous</a> |</li>
        <li><a href="contents.html">Mod_python v3.5.0-3.5.0 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; <a href="copyright.html">Copyright</a> 1990-2013, Apache Software Foundation, Gregory Trubetskoy.
      Last updated on Nov 13, 2013.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>
  </body>
</html>